<?php

namespace mbilling\BillingBundle\Model;

use Doctrine\ORM\EntityManager;
use mbilling\BillingBundle\Entity\ordersTarifsTerms;

Class OrdersTarifsTermsModel
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

    public function findAll()
    {
        $tarifsTerm = $this->em->getRepository('BillingBundle:ordersTarifsTerms')->findAll();
        return $tarifsTerm;
    }
    
    public function findByPK($tarifsTerm_id)
    {
        $tarifsTerm = $this->em->find('BillingBundle:ordersTarifsTerms', $tarifsTerm_id);
        return $tarifsTerm;
    }

    public function findByTarif($tarif_id, $tarif_type_id)
    {
        $tarifsTerm = $this->em->getRepository('BillingBundle:ordersTarifsTerms')->findBy(array('tarif_id' => $tarif_id, 'tarif_type_id' => $tarif_type_id));
        return $tarifsTerm;
    }

    public function findOneByTarif($tarif_id, $tarif_type_id)
    {
        $tarifsTerm = $this->em->getRepository('BillingBundle:ordersTarifsTerms')->findOneBy(array('tarif_id' => $tarif_id, 'tarif_type_id' => $tarif_type_id));
        return $tarifsTerm;
    }
    
    public function findByTarifAndTerm($tarif_id, $term)
    {
        $tarifsTerm = $this->em->getRepository('BillingBundle:ordersTarifsTerms')->findOneBy(array('tarif_id' => $tarif_id, 'term' => $term));
        return $tarifsTerm;
    }
    
    public function findShared()
    {
        $tarifsTerm = $this->em->getRepository('BillingBundle:ordersTarifsTerms')->findBy(array('tarif_type_id' => '1'));
        return $tarifsTerm;
    }

    public function create($oEntity)
    {
        $this->em->persist($oEntity);
        $this->em->flush();
    }

    public function removeByPK($tarifsTerm_id)
    {
        $tarifsTerm = $this->em->find('BillingBundle:ordersTarifsTerms', $tarifsTerm_id);
        $this->em->remove($tarifsTerm);
        $this->em->flush();
    } 
}
?>
